package com.lzm.seckill.server.controller;

import com.lzm.seckill.api.enums.StatusCode;
import com.lzm.seckill.api.response.BaseResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Description:
 *
 * @Author: Liuzemin
 * @Date: 2020/9/14 16:20
 */

@Controller
@RequestMapping(value = "/base")
public class BaseController {
    private final static Logger log = LoggerFactory.getLogger(BaseController.class);

    @GetMapping(value = "/welcome")
    public String welcome(String name, ModelMap modelMap){
        if (StringUtils.isBlank(name)){
            name = "这是welcome页面";
        }
        modelMap.put("name", name);
        return "welcome";
    }

    @GetMapping(value = "/data")
    @ResponseBody
    public String data(String name){
        if (StringUtils.isBlank(name)){
            name = "大帅";
        }
        return name;
    }

    /**
     * 标准请求-响应数据格式
     * @param name
     * @return
     */
    @GetMapping(value = "/response")
    @ResponseBody
    public BaseResponse response(String name){
        BaseResponse response=new BaseResponse(StatusCode.Success);
        if (StringUtils.isBlank(name)){
            name="这是welcome!";
        }
        response.setData(name);
        return response;
    }

    @GetMapping(value = "/error")
    public String error(){
        return "error";
    }
}
